package com.hxkcloud.patient.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.hxkcloud.patient.R;
import com.hxkcloud.patient.beans.DpatientInfoBean;

import java.util.List;

/**
 * ProjectName: YJHCuzhong
 * PackageName: com.yjhcloud.patient.adapter
 * Description:
 * Create by Ray.
 * Date: 2016/10/14 12:56
 */
public class AllReportApater extends BaseAdapter {
    private List<DpatientInfoBean> kinds;

    private LayoutInflater mInflater;//得到一个LayoutInfalter对象用来导入布局

    private DisplayListener listener;

    private Context context;

    private String reportId;


    /**构造函数*/
    public AllReportApater(Context context, List<DpatientInfoBean> kinds,String reportId) {
        this.mInflater = LayoutInflater.from(context);
        this.kinds = kinds;
        this.context = context;
        this.reportId = reportId;
    }

    public void setData(List<DpatientInfoBean> kinds,String reportId){
        this.kinds = kinds;
        this.reportId = reportId;
        this.notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return kinds.size();//返回数组的长度
    }

    @Override
    public Object getItem(int position) {
        return kinds.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    /**书中详细解释该方法*/
    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        final ViewHolder holder;
        //观察convertView随ListView滚动情况
        Log.v("MyListViewBase", "getView " + position + " " + convertView);
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.kind_item_list,null);
            holder = new ViewHolder();
            /**得到各个控件的对象*/
            holder.layout = (LinearLayout) convertView.findViewById(R.id.kind_layout);
            holder.name = (TextView) convertView.findViewById(R.id.kind_tv_name);
            holder.ischoose = (Button) convertView.findViewById(R.id.kind_btn);
            convertView.setTag(holder);//绑定ViewHolder对象
        }
        else{
            holder = (ViewHolder)convertView.getTag();//取出ViewHolder对象
        }
        /**设置TextView显示的内容，即我们存放在动态数组中的数据*/
        holder.name.setText(kinds.get(position).getItemName());
        holder.ischoose.setVisibility(View.INVISIBLE);

        if(reportId.equals(kinds.get(position).getItemId())){
            holder.layout.setVisibility(View.GONE);
        }else{
            holder.layout.setVisibility(View.VISIBLE);
        }




        return convertView;
    }



    /**存放控件*/
    public final class ViewHolder{
        public LinearLayout layout;
        public TextView name;
        public Button ischoose;
    }

    public interface DisplayListener {
        void onDisplay(int position);
    }

    public void setDisplayListener(DisplayListener listener){
        this.listener = listener;
    }
}
